Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

285
Visualizações
Javascript audio giving "The element has no supported sources" error on play

I'm making my first javascript game (Snake), and I've already finished most of it. Now I'm trying to add sound, but it's not working. I'm not using a server, I'm using a local html file.

This is the constructor method of the class where I'm trying to play a sound:

constructor(){
    ...
    this.collect_wav = new Audio("Sounds\\Coin.wav");
    ...
}

And later in one of the methods:

relocate(){
    ...
    this.collect_wav.play();
}

When the code runs, the new Audio runs without an error, but on the line play(), I get this error in the developer console: The error I get There is a "Sounds" folder in the same directory as my html file, and inside that folder is Coin.wav, so I think the path is correct, but it just doesn't work. But when I go into the developer console, and go to the sources tab, I don't even see the Sounds folder listed, only the html, css, and javascript files are there: Files

I have tried using the html tag like this:

<audio controls>
    <source src="Sounds/Coin.wav" type="audio/wav">
</audio>

Even this doesn't work, I see the controls show up, but it is greyed out and cannot be interacted with:

Greyed out controls

I have also tried replacing the backslashes with a normal slash (Because I'm not sure which one is correct in html), but this also didn't help. I have been trying to fix this for days, and I really have no idea what's wrong.

Edit: I've found the problem, it's something wrong with the wav file I'm using, when I changed it to a random wav file I downloaded from the internet, it worked. Then it stops working when I change it back to the original wav. So I guess it's just something wrong with the wav file I'm using.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda